import wx

class MyFrame(wx.Frame):
    def __init__(self):
        # 创建窗体
        super().__init__(None, title = '单选按钮样例', size = (600, 800))
        panel = wx.Panel(self)

        rb1 = wx.RadioButton(panel, id=1, label = '男', style = wx.RB_GROUP)
        rb2 = wx.RadioButton(panel, id=2, label = '女')
        rb3 = wx.RadioButton(panel, id=3, label = '中性')
        # 水平布局
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(rb1)
        hbox.Add(rb2)
        hbox.Add(rb3)
        panel.SetSizer(hbox)
        # id = 1，表示起始的按钮是id为1的RadioButton
        # id2 = 3，表示结束的按钮是id为3的RadioButton
        self.Bind(wx.EVT_RADIOBUTTON, self.radio_change, id = 1, id2 = 3)

    def radio_change(self, event):
        obj = event.GetEventObject()
        print(f'选项切换，选项值：{obj.GetLabel()}')

app = wx.App()
window = MyFrame()
window.Show()
app.MainLoop()